/**
 * Straight Mergesort
 */
package mergesort;

import java.util.List;

import _general.ObjectInterface;
import _general.problem.SortAlgorithm;

/**
 * @author acid
 * @param <E>
 *
 */
public class StraightMergesort extends SortAlgorithm {

	
	
	public StraightMergesort(List<ObjectInterface> unsortList) {
		super(unsortList);
		setName("Straight Mergesort");
	}
	
	public StraightMergesort() {	
		setName("Straight Mergesort");
	}
	
	@Override
	public void start () {
		int left = 0, right = getElementList().size() - 1;
		int sortsize = 1;
		int rg;
		
		while(sortsize < right) {
			rg = left - 1;
			while ((rg + sortsize) < right) {
				int seq1l = rg + 1;
				int seq1r = seq1l + sortsize - 1;
				if ((seq1r + sortsize) <= right) {
					rg = seq1r + sortsize;
				} else {
					rg = right;
				}
				merge (getElementList(), seq1l, seq1r, rg);
			}
			sortsize *= 2;
		}
	}
}
